
package com.mybatis.spring;

import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.type.AnnotationMetadata;

import com.mybatis.anno.MpperScanner;

public class MapperImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar , ResourceLoaderAware {
	ResourceLoader resourceLoader;
	@Override
	public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
		AnnotationAttributes annoAttrs = AnnotationAttributes.fromMap(importingClassMetadata.getAnnotationAttributes(MpperScanner.class.getName()));
        String[] basePackages = annoAttrs.getStringArray("value");
        //自定义的 包扫描器
        MapperClassPathBeanDefinitionScanner scanHandle = new MapperClassPathBeanDefinitionScanner(registry,false);
        //扫描指定路径下的接口
        scanHandle.doScan(basePackages);
	}
	@Override
	public void setResourceLoader(ResourceLoader resourceLoader) {
		 this.resourceLoader = resourceLoader;
	}
}
